import UIAbility from '@ohos.app.ability.UIAbility';
import window from '@ohos.window';

/**
 * 应用主能力入口
 */
export default class MainAbility extends UIAbility {
  onCreate(want, launchParam): void {
    console.log('MainAbility onCreate');
  }

  onDestroy(): void {
    console.log('MainAbility onDestroy');
  }

  onWindowStageCreate(windowStage: window.WindowStage): void {
    console.log('MainAbility onWindowStageCreate');
    
    // 设置窗口的UI加载路径
    windowStage.loadContent('pages/Index', (err, data) => {
      if (err.code) {
        console.error('Failed to load the content. Cause: ', JSON.stringify(err));
        return;
      }
      console.info('Succeeded in loading the content. Data: ', JSON.stringify(data));
    });
  }

  onWindowStageDestroy(): void {
    console.log('MainAbility onWindowStageDestroy');
  }

  onForeground(): void {
    console.log('MainAbility onForeground');
  }

  onBackground(): void {
    console.log('MainAbility onBackground');
  }
}